// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

Ext.QuickTips.init();

Ext.apply(Ext.form.BasicForm.prototype, {
	trackResetOnLoad: true
});

Ext.apply(Ext.form.Field.prototype, {
	labelSeparator: '',
	msgTarget: 'side'
});

Ext.apply(Ext.form.FormPanel.prototype, {
	baseCls: 'x-plain',
	defaults: { autoHeight: true },
	defaultType: 'fieldset',
	labelAlign: 'right',
	monitorValid: true
});

Ext.apply(Ext.grid.GridView.prototype, {
	forceFit: true
})

Ext.apply(Ext.grid.GroupingView.prototype, {
	groupTextTpl: '{text} ({[values.rs.length]})',
	hideGroupedColumn: true
});

Ext.apply(Ext.Ajax, {
	disableCaching: false,
	method: 'GET'
});

Ext.apply(Ext.TabPanel.prototype, {
	activeTab: 0,
	plain: true
});

Ext.BLANK_IMAGE_URL = '/ext-2.0/resources/images/default/s.gif';

function button(text, handler, config) {
	return Ext.apply({ handler: handler, text: text }, config);
}

function getForm() {
	return Wol.VIEWPORT.items.first().getForm();
}

function hideActiveWindow() {
	var window = Ext.WindowMgr.getActive();
	
	if(window) {
		window.hide();
		
		if(window == Ext.Msg.getDialog()) {
			Ext.Msg.updateProgress(0, '&#160;');
		}
	}
}

function load() {
	getForm().load({
		failure: function(form, action) { alert(action.failureType == Ext.form.Action.CONNECT_FAILURE ? Ext.form.Action.CONNECT_FAILURE_MSG : Ext.form.Action.LOAD_FAILURE_MSG); },
		method: 'GET',
		waitMsg: Ext.form.Action.Load.WAIT_MSG
	});
}

function reset() {
	getForm().reset();
}

function submit(success, method) {
	getForm().submit({
		failure: function(form, action) { alert(action.failureType == Ext.form.Action.CONNECT_FAILURE ? Ext.form.Action.CONNECT_FAILURE_MSG : Ext.form.Action.SERVER_INVALID_MSG); },
		method: method,
		success: success,
		waitMsg: Ext.form.Action.Submit.WAIT_MSG
	});
}

function dateColumn(name) {
	return { name: name, type: 'date', dateFormat: 'Y-m-d H:i:s' };
}

Ext.namespace('Wol');
